package com.bkgy.modular.configureRules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.RigidSeedGrading2130Dto;
import com.bkgy.modular.configureRules.entity.RigidSeedGrading2130;
import com.bkgy.modular.configureRules.mapper.RigidSeedGrading2130Mapper;
import com.bkgy.modular.configureRules.service.RigidSeedGrading2130Srvice;
import com.bkgy.sys.common.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName RigidSeedGrading2130SrviceImpl
 * @date 2023/4/19 10:30
 */
@Service
public class RigidSeedGrading2130SrviceImpl extends ServiceImpl<RigidSeedGrading2130Mapper, RigidSeedGrading2130> implements RigidSeedGrading2130Srvice {

    @Resource
    private RigidSeedGrading2130Mapper mapper;

    @Override
    public ResultData queryRigidSeedGrading2130() {
        List<RigidSeedGrading2130> rigidSeedGrading2130s = mapper.selectList(null);
        return ResultData.ResultDataFaultSelf("操作成功",rigidSeedGrading2130s);
    }

    @Override
    public ResultData updateRigidSeedGrading2130(RigidSeedGrading2130Dto dto) {
        String inner_grade = dto.getInner_grade();
        Double yp_class = dto.getYp_class();
        Double group_id = dto.getGroup_id();
        String remarks = dto.getRemarks();
        Double yield = dto.getYield();
        if (StringUtils.isEmpty(inner_grade)) {
            return ResultData.ResultDataFaultSelf("参数有误,请检查参数",-1);
        }

        LambdaQueryWrapper<RigidSeedGrading2130> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RigidSeedGrading2130::getInner_grade,inner_grade);

        RigidSeedGrading2130 rigidSeedGrading2130 = mapper.selectOne(queryWrapper);
        rigidSeedGrading2130.setGroup_id(group_id);
        rigidSeedGrading2130.setYp_class(yp_class);
        rigidSeedGrading2130.setYield(yield);
        rigidSeedGrading2130.setRemarks(remarks);

        int flag = mapper.update(rigidSeedGrading2130, queryWrapper);
        if (flag == 1) {
            return ResultData.ResultDataFaultSelf("操作成功",1);
        }
        return ResultData.ResultDataFaultSelf("操作失败",-1);
    }
}
